<template>
  <div class="drawer-container">
    <el-form
      ref="form"
      :model="formData"
      label-width="80px"
      class="formContent"
    >
      <BiForm v-if="formData.id==='' || !formData.id">
        <div class="content-outer">
          <miniAppSelect
            :multiple="false"
            @result="miniAppResult"
          />
        </div>
      </BiForm>
      <div class="content">
        <el-radio-group v-model="formData.type">
          <el-radio label="1">文字</el-radio>
          <el-radio label="2">图片</el-radio>
        </el-radio-group>
        <div
          v-if="formData.type==='1'"
          class="textArae"
        >
          <el-input
            v-model="formData.content"
            clearable
            type="textarea"
            class="textarea"
            placeholder="请输入描述信息"
          >
          </el-input>
        </div>
        <div
          v-else
          class="upload rowFlex columnCenter"
        >
          <upload
            :url="imageList"
            @resultUpload="resultUpload"
          ></upload>
        </div>
      </div>
      <el-form-item
        label="支付状态"
        style="margin-top:10px;"
      >
        <el-radio-group v-model="formData.pay_status">
          <el-radio label="0">全部</el-radio>
          <el-radio label="1">已支付</el-radio>
          <el-radio label="2">未支付</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div class="dialog-footer rowFlex">
      <el-button
        class="btn"
        @click="close"
      >取 消</el-button>
      <el-button
        :loading="loading"
        class="btn"
        type="primary"
        @click="submit"
      >确 定</el-button>
    </div>
  </div>
</template>

<script>
import upload from '@/common/component/upload.vue'
import miniAppSelect from '@/common/component/form/miniAppSelect.vue'
export default {
  components: {
    upload,
    miniAppSelect
  },
  props: {
    drawerTitle: {
      type: String,
      default: ''
    },
    row: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      loading: false,
      formData: {
        mini_app_id: '',
        // 1文字，2图片
        type: '1',
        content: '',
        // 0 全部，1已支付，2未支付
        pay_status: '0'
        // id:''
      },
      imageList: ''
    }
  },
  mounted() {
    console.log(this.row)
    if (this.row.id) {
      const { mini_app_id, type, pay_status, content, id } = this.row
      this.formData = {
        mini_app_id,
        type,
        pay_status,
        content,
        id
      }
      if (type == 2) {
        this.imageList = content
        this.formData.content = ''
      }
    }
  },
  methods: {
    close() {
      this.$emit('cancel')
    },
    miniAppResult(value) {
      this.formData.mini_app_id = value
    },
    resultUpload(result) {
      console.log(result, 'result')
      this.imageList = result
    },
    submit() {
      if (this.row?.id) {
        this.formData.id = this.row.id
      }
      if (this.formData.type === '2') {
        this.formData.content = this.imageList
      }
      // if (this.formData.mini_app_id === '') {
      //   this.$message.warning('请选择新增的小程序')
      // }

      this.$emit('ok', this.formData)
    }
  }
}
</script>
<style lang="scss" scoped>
.drawer-container {
  height: 100%;
  .formContent {
    padding: 20px;
  }
  .content {
    width: calc(100%-40px);
    height: 238px;
    background: #f7f7f7;
    border-radius: 4px;
    padding: 20px;
    .textArae {
      margin-top: 15px;
    }
    .textarea {
      width: 100%;
      height: 183px;
      ::v-deep .el-textarea__inner {
        height: 163px;
      }
    }
    .upload {
      width: 100%;
      height: 163px;
      background: #fff;
      border-radius: 4px;
      margin-top: 20px;
      padding: 20px;
    }
  }
  .imageItem {
    width: 100px;
    height: 100px;
    margin-right: 20px;
    border-radius: 5px;
  }
}
</style>